package com.bw.servlet;

import com.bw.dao.UserDao;
import com.bw.pojo.User;
import com.bw.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/***************************
 FileAction:

 CreateTime:2022-08-23 9:20
 Author:Aaking-aline
 ****************************/
@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtil.getSqlSessionFactory();
		SqlSession sqlSession = sqlSessionFactory.openSession(true);

		System.out.println(request.getParameter("id"));

		UserDao mapper = sqlSession.getMapper(UserDao.class);
		User user = new User(Integer.parseInt(request.getParameter("id")), request.getParameter("username"), request.getParameter("password"), request.getParameter("joinTime"));

		mapper.updateUser(user);
		sqlSession.close();
	}
}
